/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.osdtsystem.hierarchy.io;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import org.osdtsystem.hierarchy.Hierarchy;

/**
 * Interface for writing a hierarchy to a string.
 * @author Matthias Buch-Kromann
 */
public interface HierarchyIO {
    /**
     * Read a hierarchy from a character reader.
     * @param manager a hierarchy manager
     * @param reader the character reader for an encoded hierarchy
     * @return the resulting hierarchy
     * @throws IOException if an input/output error occurs in the reader
     */
    public Hierarchy<?> read(HierarchyManager manager, Reader reader)
            throws IOException;

    /**
     * Write a hierarchy to a character writer.
     * @param manager a hierarchy manager
     * @param hierarchy the hierarchy
     * @param writer the character writer
     * @return the list of direct subhierarchies used by the hierarchy
     * @throws IOException if an input/output error occurs in the writer
     * @throws UnsupportedOperationException whenever the hierarchy writer does not
     * support writing hierarchies of the given type to writers of the given type.
     */
    public Hierarchy<?>[] write(HierarchyManager manager, Hierarchy<?> hierarchy, Writer writer)
            throws IOException;
}
